package edu.wpi.cs509.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.*;

import edu.wpi.cs509.ui.menu.MenuActionQuit;

/**
 * Panel to be used to draw login screen
 * 
 * @author jprocess
 *
 */

@SuppressWarnings("serial")
public class LoginScreenPanel extends JPanel {
	
	private JTextField userNameText;
	private JPasswordField passwordText;
	private JTextField serverHostText;
	
	/**
	 * Constructor for the client application
	 */
	public LoginScreenPanel( A__MainStrategoClient client ) {
		
		// Create label and text field for login name
	    JLabel nameLabel = new JLabel("Login Name: ");
	    nameLabel.setLabelFor(userNameText);
	    
	    userNameText = new JTextField(16);
	    userNameText.setText("user1");		// for testing	

	    // Create label and text field for password
	    JLabel pwLabel = new JLabel("Password: ");
	    pwLabel.setLabelFor(passwordText);

	    passwordText = new JPasswordField(16);
	    passwordText.setText("cs509");		// for testing	

		// Create label and text field for server host
	    JLabel serverLabel = new JLabel("Server IP: ");
	    serverLabel.setLabelFor(serverHostText); 
		
	    serverHostText = new JTextField(16);
	    serverHostText.setText("127.0.0.1");		// for testing	
	    
	    // Create quit and login buttons
	    JButton quitButton = new JButton("Quit");
	    quitButton.addActionListener(new MenuActionQuit(client));
	    JButton loginButton = new JButton("Login");
	    loginButton.addActionListener(new LoginButtonAction(client, this));
	  
	    // Position the buttons, labels, and text fields
	    GridBagConstraints c = new GridBagConstraints(); // Holds constraints for GUI components.
	    GridBagLayout gridbag = new GridBagLayout();
	    setLayout(gridbag);
	
	    c.gridx = 0;
	    c.gridy = 0;
	    gridbag.setConstraints(nameLabel, c);
	    add(nameLabel);

	    c.gridx = 100;
	    c.gridy = 0;
	    gridbag.setConstraints(userNameText, c);
	    add(userNameText);

	    c.gridx = 0;
	    c.gridy = 120;
	    gridbag.setConstraints(pwLabel, c);
	    add(pwLabel);

	    c.gridx = 100;
	    c.gridy = 120;
	    gridbag.setConstraints(passwordText, c);
	    add(passwordText);
	    
	    c.gridx = 0;
	    c.gridy = 240;
	    gridbag.setConstraints(serverLabel, c);
	    add(serverLabel);
	    
	    c.gridx = 100;
	    c.gridy = 240;
	    gridbag.setConstraints(serverHostText, c);
	    add(serverHostText);
	    
	    c.gridx = 0;
	    c.gridy = 360;
	    gridbag.setConstraints(quitButton, c);
	    add(quitButton);
	    
	    c.gridx = 100;
	    c.gridy = 360;
	    gridbag.setConstraints(loginButton, c);
	    add(loginButton);
	    
	}
	
	/**
	 * Get method to return text in the User Name box
	 * @return
	 */
	public String getUserName() {
		return userNameText.getText();
	}
	
	/**
	 * Get method to return text in the Password box
	 * @return
	 */
	public String getPassword() {
		char[] pass = passwordText.getPassword();
		return new String(pass);
	}
	
	/**
	 * Get method to return the text in Server IP box
	 * @return
	 */
	public String getHost() {
		return serverHostText.getText();
	}
}
